"""
房间数据映射层
"""


class RoomMapper:
    """房间数据映射 - 调用模型的转换方法"""
    
    def to_dict(self, room, include_relations=True):
        """将Room模型转换为字典"""
        if not room:
            return None
        return room.to_dict(include_relations=include_relations)
    
    def to_list(self, rooms, include_relations=True):
        """将Room列表转换为字典列表"""
        return [room.to_dict(include_relations=include_relations) for room in rooms]
    
    def from_dict(self, data):
        """从字典提取Room数据（用于更新）"""
        # 返回可用于更新模型的字典
        update_data = {}
        if 'roomNumber' in data:
            update_data['room_number'] = data['roomNumber']
        if 'floor' in data:
            update_data['floor'] = data['floor']
        if 'roomTypeId' in data:
            update_data['room_type_id'] = data['roomTypeId']
        if 'area' in data:
            update_data['area'] = data['area']
        if 'bedType' in data:
            update_data['bed_type'] = data['bedType']
        if 'maxGuests' in data:
            update_data['max_guests'] = data.get('maxGuests', 2)
        if 'roomStatusId' in data:
            update_data['room_status_id'] = data.get('roomStatusId', 1)
        if 'description' in data:
            update_data['description'] = data.get('description')
        return update_data
